import { Inject, Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { CommunityPostEntity } from '../entity/post';
import { CoolCommException } from '@cool-midway/core';

/**
 * 社区帖子
 */
@Provide()
export class CommunityPostService extends BaseService {
  @InjectEntityModel(CommunityPostEntity)
  communityPostEntity: Repository<CommunityPostEntity>;

  /**
   * 增加浏览数
   * @param id
   */
  async addViewCount(id: number) {
    await this.communityPostEntity.increment({ id }, 'viewCount', 1);
  }

  /**
   * 增加点赞数
   * @param id
   */
  async addLikeCount(id: number) {
    await this.communityPostEntity.increment({ id }, 'likeCount', 1);
  }
}
